home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / utility / utilhard / lcdaem18.lha / LCDaemon / Programmer / parallel.c < prev    next >
C/C++ Source or Header  |  1996-10-13  |  3KB  |  89 lines

  1. /****************************************************************************\
  2. **                                                                            **
  3. \****************************************************************************/
  4. #include <proto/exec.h>
  5. #include <proto/misc.h>
  6. #include <devices/timer.h>
  7. #include <resources/misc.h>
  8. #include <hardware/cia.h>
  9. #include "lcd.h"
  10. #define MINDELAY    80            /* delay for device to complete request */
  11.  
  12. struct Library *MiscBase=NULL;
  13. extern struct timerequest *timereq;
  14. extern struct CIA ciaa,ciab;
  15. extern char *startup;        /*    if non-NULL, points to startup options    */
  16. BOOL portopen=FALSE,bitsopen=FALSE;
  17.  
  18. /****************************************************************************\
  19. **    Allocate everything needed for port access                                **
  20. **                                                                            **
  21. **    Return 0 for success.                                                    **
  22. \****************************************************************************/
  23. long lcd_alloc(struct lcdparams *param){
  24.     BOOL success=TRUE;
  25.     if(!(MiscBase=OpenResource("misc.resource"))) success=FALSE;
  26.     if(!(portopen=(BOOL)!AllocMiscResource(MR_PARALLELPORT,"pario"))) success=FALSE;
  27.     if(!(bitsopen=(BOOL)!AllocMiscResource(MR_PARALLELBITS,"pario"))) success=FALSE;
  28.     if(success){
  29.         ciaa.ciaprb=(UBYTE)0x00;
  30.         ciaa.ciaddrb=(UBYTE)0xff;        /*    Put data lines as output        */
  31.         ciab.ciapra&=~(UBYTE)0x03;
  32.         ciab.ciaddra|=(UBYTE)0x03;        /*    Put control lines as output        */
  33.     }
  34.     return(success);
  35. }
  36.  
  37. /****************************************************************************\
  38. **    Free everything allocated.                                                **
  39. **                                                                            **
  40. **    lcd_free() is called even when lcd_alloc() failed, to allow for            **
  41. **    freeing the successful allocations in lcd_alloc()                        **
  42. \****************************************************************************/
  43. void lcd_free(void){
  44.     if(portopen) FreeMiscResource(MR_PARALLELPORT);
  45.     if(bitsopen) FreeMiscResource(MR_PARALLELBITS);
  46. }
  47.  
  48. /****************************************************************************\
  49. **    AmigaDOS Delay(), but using microseconds                                **
  50. \****************************************************************************/
  51. void lcd_delayfor(int micros){
  52.     timereq->tr_node.io_Command=TR_ADDREQUEST;
  53.     timereq->tr_time.tv_micro=micros%1000000;
  54.     timereq->tr_time.tv_secs=micros/1000000;
  55.     DoIO((struct IORequest *)timereq);    
  56. }
  57.  
  58. /****************************************************************************\
  59. **    Send code to LCD, with pause for LCD to comply                            **
  60. **                                                                            **
  61. **    Hardware:                                                                **
  62. **                                                                            **
  63. **    Centronics            LCD                                                    **
  64. **    D0...D7        ->        d0...d7                                                **
  65. **    BUSY        ->        Enable                                                **
  66. **    POUT        ->        Register Select                                        **
  67. **                                                                            **
  68. \****************************************************************************/
  69. void lcd_putchar(UBYTE code,BOOL data,long micros){
  70.     if(micros<MINDELAY) micros=MINDELAY;
  71.     ciaa.ciaddrb=0xff;                    /*    Parallel lines as output        */
  72.     ciaa.ciaprb=code;                    /*    Put code on parallel data lines    */
  73.     if(!data){
  74.         ciab.ciapra&=~((UBYTE)0x02);    /*    Data=0    ->    RS=1                */
  75.     } else {
  76.         ciab.ciapra|=(UBYTE)0x02;        /*    Data=1    ->    RS=1                */
  77.     }
  78.  
  79.     lcd_delayfor(1);
  80.     ciab.ciapra|=(UBYTE)0x01;            /*    Assert E line                    */
  81.     lcd_delayfor(1);
  82.  
  83.     ciab.ciapra&=~((UBYTE)0x01);        /*    Disable E after 1000 ns            */
  84.     
  85.     lcd_delayfor(micros);                /*    Wait while LCD processes...        */
  86.  
  87.     ciaa.ciaddrb=0x00;                    /*    float D0-D7 again (saves power)    */
  88. }
  89.